import arcpy
import sys
reload(sys)
sys.setdefaultencoding('utf8')

def check_point_field(tar, field_name):
    try:
        arcpy.DeleteField_management(tar, [field_name])
    except Exception:
        pass
    finally:
        arcpy.AddField_management(
            tar,
            field_type="TEXT",
            field_name=field_name)

def main():
    check_point_field(arcpy.GetParameterAsText(0), arcpy.GetParameterAsText(3))

    with arcpy.da.UpdateCursor(arcpy.GetParameterAsText(0), ["SHAPE@", arcpy.GetParameterAsText(3)]) as point_rows:
        for row in point_rows:
            page_number = []
            with arcpy.da.SearchCursor(arcpy.GetParameterAsText(1), ["SHAPE@", arcpy.GetParameterAsText(2)]) as polygon_rows:
                for eachPolygon in polygon_rows:
                    if eachPolygon[0].contains(row[0]):
                        page_number.append(str(eachPolygon[1]))

            row[1] = ','.join(page_number)
            point_rows.updateRow(row)

    arcpy.AddMessage('main success !! >>>> Please flush the cache <<<<<')

main()
